import { Component } from '@angular/core';
import {IonicPage, NavController, NavParams, ViewController} from 'ionic-angular';
import {InfoProvider} from "../../providers/InfoProvider";

/**
 * Generated class for the StockSelectPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-stock-select',
  templateUrl: 'stock-select.html',
})
export class StockSelectPage {

    quotation_type: string = null;
    custom_info: any[] = [
        {
            title: '贵金属',
            value: 'gjs'
        },
        {
            title: '外汇',
            value: 'wh'
        },
        {
            title: '股指',
            value: 'gz'
        },
        {
            title: '原油',
            value: 'yy'
        },
    ];
    custom_items: any[] = [];

    constructor(public navCtrl: NavController, public navParams: NavParams,
                private viewCtrl: ViewController,
                private infoProvider: InfoProvider) {
        infoProvider.getIndexCustom().then(data => {
            this.custom_items = data;
            this.quotation_type = 'gjs';
            console.log(this.custom_items);
        });
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad StockSelectPage');
    }

    onSegmentChanged(event) {

    }

    onClosed() {
        this.viewCtrl.dismiss().then();
    }

    onConfirm() {
        this.viewCtrl.dismiss({custom: this.custom_items}).then(data => {
            if (data) {
                this.infoProvider.setIndexCustom(data.custom);
            }
        });
    }
}
